/*
 * @Author: NJ_1098 xiabaoxin
 * @Date: 2025-02-11 16:12:00
 * @LastEditors: NJ_1098 xiabaoxin
 * @LastEditTime: 2025-02-14 11:21:54
 * @Description: 统一错误状态处理
 */
const logger = require("../log/log.js");

module.exports = (err, ctx) => {
  let status = 500;
  switch (err.code) {
    case "10001":
      status = 400;
      break;
    default:
      break;
  }
  let msg = `log4j输出日志：${ctx.method} ${ctx.url} - ${err.msg}`;
  if (err.data) {
    msg = `${msg}\n${err.data}`;
  }
  logger.error(msg);
  ctx.status = status;
  ctx.body = err;
};
